//
//  MTLiveContainerController.m
//  MeToo
//
//  Created by 俊松何 on 2018/9/3.
//  Copyright © 2018年 tianxie. All rights reserved.
//

#import "MTLiveContainerController.h"
#import "MTLiveListController.h"

@interface MTLiveContainerController ()

@property(nonatomic,strong) NSMutableArray *types;

@end

@implementation MTLiveContainerController

+(MTLiveContainerController *)containerVc
{
    MTLiveContainerController *homeVc = [[MTLiveContainerController alloc] init];
    homeVc.titleColorSelected = [UIColor blackColor];
    homeVc.titleColorNormal = [UIColor lightGrayColor];
    homeVc.titleSizeNormal = 20;
    homeVc.titleSizeSelected = 20;
    homeVc.progressColor = mainTintColor;
    homeVc.menuViewStyle = WMMenuViewStyleLine;
    homeVc.progressWidth = 25;
    homeVc.progressHeight = 3;
    homeVc.progressViewCornerRadius = 1.5;
    
    homeVc.titleFontName = @"Helvetica-Bold";
    homeVc.menuViewContentMargin = 10;
    homeVc.pageAnimatable = YES;
    homeVc.automaticallyCalculatesItemWidths = YES;
    homeVc.bounces = YES;
    homeVc.itemMargin = 0;
    homeVc.menuViewLayoutMode = WMMenuViewLayoutModeLeft;
    homeVc.showOnNavigationBar = YES;
    return homeVc;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [[MTLiveApiManager manager] getshowliveTypesWithcompletion:^(NSMutableArray<MTLiveTypeModel *> *types, MTError *error) {
        if(error == nil)
        {
            self.types = types;
            [self reloadData];
        }
    }];
    
    
}
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.types.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    MTLiveTypeModel *mdoel = self.types[index];
    return mdoel.name;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    MTLiveListController *liveVc = [[MTLiveListController alloc] init];
    MTLiveTypeModel *mdoel = self.types[index];
    liveVc.typeId = mdoel.id;
    return liveVc;
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    CGFloat width = [super menuView:menu widthForItemAtIndex:index];
    return width + 20;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    CGFloat leftMargin = 0;
    CGRectGetMaxY(self.navigationController.navigationBar.frame);
    return CGRectMake(0, 30, self.view.frame.size.width - 2*leftMargin, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    
    CGFloat originY = CGRectGetMaxY(self.navigationController.navigationBar.frame);
    
    return CGRectMake(0, originY, self.view.frame.size.width, self.view.frame.size.height - originY - 50);
}




@end
